package sg.edu.nus.iss.umpire.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import sg.edu.nus.iss.umpire.dao.UmpireAssessmentDao;
import sg.edu.nus.iss.umpire.domain.UmpireAssessment;

public class UmpireAssessmentDaoImpl extends BaseDaoImpl<Long, UmpireAssessment> implements UmpireAssessmentDao {

	public UmpireAssessmentDaoImpl(EntityManager em) {
		super(em);
	}

	@Override
	public UmpireAssessment findUmpireAssessment(String umpireName) {
			String query = "SELECT FROM " + UmpireAssessment.class.getName()
					+ " umpireAssessment where umpireName=:umpireName";
			Query q = em.createQuery(query).setParameter("umpireName",
					umpireName);
			q.setHint("datanucleus.appengine.datastoreReadConsistency",
					"EVENTUAL");
			List<UmpireAssessment> umpireAssessmentList = (List<UmpireAssessment>) q
					.getResultList();
			return null != umpireAssessmentList
					&& 0 != umpireAssessmentList.size() ? umpireAssessmentList
					.get(0) : null;
	}

}
